package academic.emailClient.control.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;

import academic.emailClient.control.MessageMapper;
import academic.emailClient.model.EmailClientModel;
import academic.emailClient.model.entities.Filter;
import academic.emailClient.view.EmailClientViewInterface;

public class DeleteFilterActionListener implements ActionListener{
	
	private EmailClientViewInterface view;
	private EmailClientModel model;
	
/**
 * constructor
 * 	
 * @param view
 * @param model
 */
	public DeleteFilterActionListener(EmailClientViewInterface view, EmailClientModel model) {
		super();
		this.view = view;
		this.model = model;
	}

	/**
	 * Handle Delete Filter Action event
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		HashMap<String, String> paths=model.getAllSubfoldersPaths();
		ArrayList<Filter> filters = model.getFilters();
		Filter filter = view.getCurrentFilter(filters);
		model.deleteFilter(filter.getName());
		view.displaySuccessfulDeletion();
		view.updateMailBoxList(MessageMapper.mapToMessageViewList(model.getIboxMessages()));	
	}
}

